/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    CWI Amsterdam - initial API and implementation
 */
package nl.cwi.arne.mcrl2.toolchains;

import java.io.File;

import nl.cwi.arne.mcrl2.util.Command;
import nl.cwi.arne.mcrl2.util.MCRL2Commands;
import nl.cwi.arne.mcrl2.util.MCRL2Options;
import nl.cwi.arne.mcrl2.util.MCRL2Options.Equivalence;
import nl.cwi.arne.mcrl2.util.ToolChain;

/**
 * @author Christian Krause
 * @generated NOT
 */
public final class CompareLTSToolChain extends ToolChain {
	
	// Serial ID:
	private static final long serialVersionUID = 1L;
	
	// ltscompare command:
	private Command ltscompareCommand;
	
	// The result:
	private boolean result;
	
	/**
	 * Default constructor.
	 * @param ltsFile1 1st LTS file.
	 * @param ltsFile2 2nd LTS file.
	 * @param options MCRL2 options.
	 */
	public CompareLTSToolChain(File ltsFile1, File ltsFile2, MCRL2Options options) {
		this(ltsFile1, ltsFile2, options.getEquivalence());
	}

	/**
	 * Default constructor.
	 * @param ltsFile1 1st LTS file.
	 * @param ltsFile2 2nd LTS file.
	 * @param equivalence Equivalence type.
	 */
	public CompareLTSToolChain(File ltsFile1, File ltsFile2, Equivalence equivalence) {
		super("Comparing labeled transition systems...");
		add(ltscompareCommand = MCRL2Commands.ltscompare(ltsFile1, ltsFile2, equivalence));
		setCaptureOutput(true);
	}

	/*
	 * (non-Javadoc)
	 * @see nl.cwi.arne.mcrl2.util.ToolChain#commandFinished(nl.cwi.arne.mcrl2.util.Command)
	 */
	@Override
	protected void commandFinished(Command command) {
		super.commandFinished(command);
		if (command==ltscompareCommand) {
			String output = command.getOutput();
			String start = "LTSs are ";
			int pos = output.indexOf(start);
			if (pos<0) {
				throw new RuntimeException("ltscompare produced unexpected output");
			}
			output = output.substring(pos + start.length()).trim();
			result = !output.startsWith("not");
		}
	}
	
	public boolean getResult() {
		return result;
	}
	
}
